package com.ljj.examisto.notification

import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import com.ljj.examisto.R
import com.ljj.examisto.util.NotificationChannelInfo

object NotificationChannelManager {

    fun createChannels(context: Context) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
        val notificationManager = ContextCompat.getSystemService(
            context,
            NotificationManager::class.java
        ) ?: return
        /** 服务通知渠道 */
        val serviceChannel = NotificationChannel(
            NotificationChannelInfo.SERVICE_CHANNEL_ID,
            context.getString(R.string.notification_channel_name),
            NotificationManager.IMPORTANCE_LOW // 重要性级别（低：不发出声音或振动）
        ).apply {
            description = context.getString(R.string.notification_channel_description)
            lockscreenVisibility = NotificationCompat.VISIBILITY_SECRET // 锁屏可见性（秘密：不显示在锁屏上）
            setSound(null, null) // 禁用声音
            enableVibration(false) // 禁用振动
            setShowBadge(false) // 禁用桌面角标
            setBypassDnd(true) // 允许绕过勿扰模式
        }
        /** 考试提醒渠道 */
        val reminderChannel = NotificationChannel(
            NotificationChannelInfo.REMIND_CHANNEL_ID,
            context.getString(R.string.remind_channel_name),
            NotificationManager.IMPORTANCE_HIGH // 重要性级别（高：发出声音和振动）
        ).apply {
            description = context.getString(R.string.remind_channel_description)
            lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC // 锁屏可见
            enableLights(false) // 禁用LED灯
            enableVibration(true) // 启用振动
            vibrationPattern = longArrayOf(0, 500, 200, 500) // 振动模式
            setShowBadge(true) // 显示角标
            setBypassDnd(true) // 允许绕过勿扰模式
        }
        // 批量创建渠道
        notificationManager.createNotificationChannels(listOf(serviceChannel, reminderChannel))
    }
}